<?php
class Managearticles_Controller_Managearticles {
	
	public $template;
	
	public function main(array $getVars, array $postVars){
		try {
			if(isset($_SESSION['users_access_level']) && ($_SESSION['users_access_level'] > 4)){
				$this->getData($getVars, $postVars);
			}
			else {
				echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
			}
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
	}
	
	private function getData(array $getVars, array $postVars){
		if(isset($getVars['page'])){
			$manageArticlesModel = new Managearticles_Model_Articleactions;
			$article = $manageArticlesModel->getAction($getVars, $postVars);
			$this->template = "./managearticles/views/action.php";
		}
		else {
			$manageArticlesModel = new Managearticles_Model_Allarticles;
			$article = $manageArticlesModel->getList();
			$this->template = "./managearticles/views/articlelist.php";
		}
		$view = new Core_Model_View($this->template);
		$view->assign('article', $article);
	}
}